#提供作业与评分相关工具函数,如作业格式验证、成绩加权计算
from datetime import datetime

def validate_assignment_format(submission_content, required_format):
    """验证作业提交格式是否符合要求"""
    # 简单示例:根据文件扩展名判断,实际可根据具体格式验证逻辑修改
    if required_format.lower() == "pdf" and not submission_content.lower().endswith(".pdf"):
        return False
    elif required_format.lower() == "py" and not submission_content.lower().endswith(".py"):
        return False
    return True

def calculate_weighted_score(task_scores, task_weights):
    """计算加权分数"""
    total_weight = sum(task_weights.values())
    # 若权重和不为1,进行归一化
    normalized_weights = {task_id: weight / total_weight for task_id, weight in task_weights.items()}
    weighted_score = 0
    for task_id, score in task_scores.items():
        if task_id in normalized_weights:
            weighted_score += score * normalized_weights[task_id]
    return weighted_score

def check_late_submission(submit_time_str, due_date_str):
    """检查提交是否迟交"""
    submit_time = datetime.strptime(submit_time_str, "%Y-%m-%d %H:%M")
    due_date = datetime.strptime(due_date_str, "%Y-%m-%d %H:%M")
    return submit_time > due_date